package com.boarsoft.boar.sys.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.LogonI;
import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.sys.SysUserBiz;
import com.boarsoft.boar.sys.entity.SysUser;
import com.boarsoft.common.Authorized;
import com.boarsoft.web.login.Logined;

@RestController
@RequestMapping("/sys/password")
public class SysPasswordAction {
	@Autowired
	private SysUserBiz sysUserBiz;

	/**
	 * 管理员修改系统用户密码
	 * 
	 * @return
	 */
	@RequestMapping("/reset.do")
	@Authorized(code = "sys.password.reset")
	public ReplyInfo<Object> reset(String id, String password) {
		SysUser o = sysUserBiz.get(id);
		o.setPassword(password);
		sysUserBiz.update(o);
		return ReplyInfo.SUCCESS;
	}

	/**
	 * 员工自己修改密码
	 * 
	 * @return
	 */
	@RequestMapping("/change.do")
	@Authorized(code = "sys.password.change")
	public ReplyInfo<Object> change(@Logined LogonI<String> logon, String password) {
		SysUser o = sysUserBiz.get(logon.getId());// sysPowerBiz.getUserIdByToken(token)
		o.setPassword(password);
		sysUserBiz.update(o);
		return ReplyInfo.SUCCESS;
	}
}